package com.ruoyi.xmglkbgl.tpzs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.xmglkbgl.tpzs.service.ITpzsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.xmglkbgl.tpzs.domain.Tpzs;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片展示Controller
 *
 * @author huacai
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/xmgl/tpzs")
public class TpzsController extends BaseController
{
    @Autowired
    private ITpzsService tpzsService;

    /**
     * 查询图片展示列表
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tpzs tpzs)
    {
        startPage();
        List<Tpzs> list = tpzsService.selectTpzsList(tpzs);
        return getDataTable(list);
    }

    /**
     * 导出图片展示列表
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:export')")
    @Log(title = "图片展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tpzs tpzs)
    {
        List<Tpzs> list = tpzsService.selectTpzsList(tpzs);
        ExcelUtil<Tpzs> util = new ExcelUtil<Tpzs>(Tpzs.class);
        util.exportExcel(response, list, "图片展示数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Tpzs> util = new ExcelUtil<Tpzs>(Tpzs.class);
        util.importTemplateExcel(response, "图片展示数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "图片展示", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<Tpzs> util = new ExcelUtil<Tpzs>(Tpzs.class);
        InputStream inputStream = file.getInputStream();
        List<Tpzs> list = util.importExcel(inputStream );
        inputStream.close();
        int count = tpzsService.batchInsertTpzs(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取图片展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:query')")
    @GetMapping(value = "/{tpzsId}")
    public AjaxResult getInfo(@PathVariable("tpzsId") String tpzsId)
    {
        return success(tpzsService.selectTpzsByTpzsId(tpzsId));
    }

    /**
     * 新增图片展示
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:add')")
    @Log(title = "图片展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tpzs tpzs)
    {
        return toAjax(tpzsService.insertTpzs(tpzs));
    }

    /**
     * 修改图片展示
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:edit')")
    @Log(title = "图片展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tpzs tpzs)
    {
        return toAjax(tpzsService.updateTpzs(tpzs));
    }

    /**
     * 删除图片展示
     */
    @PreAuthorize("@ss.hasPermi('xmgl:tpzs:remove')")
    @Log(title = "图片展示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tpzsIds}")
    public AjaxResult remove(@PathVariable String[] tpzsIds)
    {
        return toAjax(tpzsService.deleteTpzsByTpzsIds(tpzsIds));
    }
}
